﻿using System;
using Tao.OpenGl;

namespace Aeon.Framework.Objects
{

/// <summary>
/// Sphere primitive class.
/// Uses up to 1 color and texture.
/// 
/// </summary>
public class Sphere : ObjectBase
    {
    // --- Attributes:
    
    private Int32 detail;       // Sphere level of detail. 
    private Single radius;      // Sphere rad.
    
    // --- Constructor:

    /// <summary>
    /// Simple sphere constructor.
    /// 
    /// </summary>
    /// <param name="key"> Unique identifier. </param>
    /// <param name="origin"> Object origin.  </param>
    /// <param name="angle"> Object orientation. </param>
    /// <param name="rad"> Sphere rad. </param>
    public Sphere(String key, Position origin, Orientation angle, Single radius)
        : this(key,origin,angle,radius,30,AeonMaterials.Default) { } 

    /// <summary>
    /// Custom sphere constructor.
    /// 
    /// </summary>
    /// <param name="key"> Unique identifier. </param>
    /// <param name="origin"> Object origin.  </param>
    /// <param name="angle"> Object orientation. </param>
    /// <param name="rad"> Sphere rad. </param>
    /// <param name="lod"> Sphere level of detail, in number of facets. </param>
    /// <param name="material"> Object material. </param>
    public Sphere(String key, Position origin, Orientation angle, Single radius, Int32 lod, AeonMaterial material)
        : base(key,origin,angle,material)
        {
        detail = lod;
        this.radius = radius;
        }
        
    // --- Public Methods:

    public override void Draw()
        {
        Gl.glTranslatef(origin.xPos,origin.yPos,origin.zPos);
        Gl.glRotatef(angle.xAng-90,1,0,0);
        Gl.glRotatef(angle.yAng,0,1,0);
        Gl.glRotatef(angle.zAng,0,0,1);
        
        Gl.glColor4f(material.Color.R,material.Color.G,material.Color.B,material.Color.A);
        material.Texture.Bind();
        
        Glu.GLUquadric quadric = Glu.gluNewQuadric();

        Glu.gluQuadricDrawStyle(quadric, Glu.GLU_FILL);
        Glu.gluQuadricNormals(quadric, Glu.GLU_SMOOTH);
        Glu.gluQuadricTexture(quadric,Gl.GL_TRUE);
        
        Glu.gluSphere(quadric, radius, detail, detail);
        
        Glu.gluDeleteQuadric(quadric);
        }

    }


}